package com.grass.p019lv.fragment;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.OnLineServiceBean;
import com.androidx.p013lv.base.bean.UserInfo;
import com.androidx.p013lv.base.glide.GlideUtils;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.model.UserInfoModel;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.LogUtils;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.TimeUtils;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.view.CircleImageView;
import com.google.android.material.appbar.AppBarLayout;
import com.grass.p019lv.databinding.FragmentMineBinding;
import com.gyf.immersionbar.ImmersionBar;
import p000a.shuyu.p005a.GSYVideoManager;

/* renamed from: com.grass.lv.fragment.MineFragment */
public class MineFragment extends LazyFragment<FragmentMineBinding> {
    private String applicationCenterUrl;
    private UserInfoModel model;
    private UserInfo userInfo;

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return R.layout.fragment_mine;
    }

    public static MineFragment newInstance() {
        Bundle bundle = new Bundle();
        MineFragment mineFragment = new MineFragment();
        mineFragment.setArguments(bundle);
        return mineFragment;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment, com.gyf.immersionbar.components.ImmersionOwner
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(((FragmentMineBinding) this.binding).toolBar).statusBarDarkFont(false).init();
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        ((FragmentMineBinding) this.binding).setClick(new OnClick());
        this.userInfo = SpUtils.getInstance().getUserInfo();
        ((FragmentMineBinding) this.binding).setUserInfo(this.userInfo);
        ((FragmentMineBinding) this.binding).mo25721c(SpUtils.getInstance().getString("domain") + this.userInfo.getLogo());
        this.model = (UserInfoModel) new ViewModelProvider(this).get(UserInfoModel.class);
        ((FragmentMineBinding) this.binding).rlBgHead.measure(0, 0);
        int measuredHeight = ((FragmentMineBinding) this.binding).rlBgHead.getMeasuredHeight();
        int actionBarHeight = ImmersionBar.getActionBarHeight(this) + ImmersionBar.getStatusBarHeight(this);
        final int i = measuredHeight - actionBarHeight;
        LogUtils.m63e("---->", i + "--" + measuredHeight + "--" + actionBarHeight);
        ((FragmentMineBinding) this.binding).appBar.addOnOffsetChangedListener((AppBarLayout.OnOffsetChangedListener) new AppBarLayout.OnOffsetChangedListener() {
            /* class com.grass.p019lv.fragment.MineFragment.C29951 */

            @Override // com.google.android.material.appbar.AppBarLayout.BaseOnOffsetChangedListener, com.google.android.material.appbar.AppBarLayout.OnOffsetChangedListener
            public void onOffsetChanged(AppBarLayout appBarLayout, int i) {
                float abs = (((float) Math.abs(i)) * 1.0f) / ((float) i);
                ((FragmentMineBinding) MineFragment.this.binding).tvTitle.setAlpha(abs);
                ((FragmentMineBinding) MineFragment.this.binding).toolBar.getBackground().setAlpha((int) (abs * 255.0f));
            }
        });
        this.model.data().observe(this, new Observer<BaseRes<UserInfo>>() {
            /* class com.grass.p019lv.fragment.MineFragment.C29962 */

            public void onChanged(BaseRes<UserInfo> baseRes) {
                if (baseRes.getCode() != 200 || baseRes.getData() == null) {
                    ToastUtils.getInstance().showWrong(baseRes.getMsg());
                    return;
                }
                MineFragment.this.userInfo = baseRes.getData();
                SpUtils.getInstance().setUserInfo(MineFragment.this.userInfo);
                ((FragmentMineBinding) MineFragment.this.binding).setUserInfo(MineFragment.this.userInfo);
                ((FragmentMineBinding) MineFragment.this.binding).mo25721c(SpUtils.getInstance().getString("domain") + MineFragment.this.userInfo.getLogo());
            }
        });
        ((FragmentMineBinding) this.binding).ivMessage.setOnClickListener(new View.OnClickListener() {
            /* class com.grass.p019lv.fragment.MineFragment.View$OnClickListenerC29973 */

            public void onClick(View view) {
                if (!MineFragment.this.isOnClick()) {
                    ARouter.getInstance().build(Constance.MESSAGE_ACTIVITY).withString(Key.TXT, "我的").navigation();
                }
            }
        });
        this.model.getOnlineServiceData().observe(this, new Observer<BaseRes<OnLineServiceBean>>() {
            /* class com.grass.p019lv.fragment.MineFragment.C29984 */

            public void onChanged(BaseRes<OnLineServiceBean> baseRes) {
                if (baseRes.getCode() == 200) {
                    MineFragment.this.applicationCenterUrl = baseRes.getData().getUrl();
                }
            }
        });
        this.model.setOnlineServiceData();
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onResume() {
        super.onResume();
        GSYVideoManager.onPause();
        this.model.getUserInfo();
    }

    public static void loadUserLogo(CircleImageView circleImageView, String str) {
        GlideUtils.loadPicHead(str, circleImageView);
    }

    public static void setUserVipData(TextView textView, UserInfo userInfo2) {
        String str;
        if (userInfo2.getFreeWatches() == -1) {
            str = "總時長 " + TimeUtils.utcToChinaTwo(userInfo2.getExpiredVip());
            textView.setTextSize(2, 12.0f);
        } else {
            int freeWatches = userInfo2.getFreeWatches() - userInfo2.getWatched();
            str = "今日觀影次數" + Math.max(freeWatches, 0) + "/" + userInfo2.getFreeWatches();
            textView.setTextSize(2, 14.0f);
        }
        textView.setText(str);
    }

    @Override // androidx.fragment.app.Fragment, com.androidx.p013lv.base.p015ui.LazyFragment
    public void onDestroyView() {
        super.onDestroyView();
        UserInfoModel userInfoModel = this.model;
        if (userInfoModel != null) {
            userInfoModel.cancelHttp();
        }
        HttpUtils.getInsatance().cancelTag("OnLineServiceBean");
    }

    /* renamed from: com.grass.lv.fragment.MineFragment$OnClick */
    public class OnClick {
        public OnClick() {
        }

        public void goSetting() {
            if (!MineFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.SETTING_ACTIVITY).navigation();
            }
        }

        public void personalInformation() {
            if (!MineFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.USER_INFO_ACTIVITY).withInt(Key.USER_ID, MineFragment.this.userInfo.getUserId()).navigation();
            }
        }

        public void userIntroduce() {
            if (!MineFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.USER_INFO_ACTIVITY).withInt(Key.USER_ID, MineFragment.this.userInfo.getUserId()).navigation();
            }
        }

        public void bindingPhone() {
            if (!MineFragment.this.isOnClick()) {
                int i = 2;
                if (!TextUtils.isEmpty(MineFragment.this.userInfo.getMobile())) {
                    i = 3;
                }
                ARouter.getInstance().build(Constance.LOGIN_ACTIVITY).withInt("type", i).navigation();
            }
        }

        public void vipCenter() {
            if (!MineFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.VIP_CENTER_ACTIVITY).withString(Key.BACK_TITLE, "我的").navigation();
            }
        }

        public void mineWallet() {
            if (!MineFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.WALLET_ACTIVITY).navigation();
            }
        }

        public void shareInvitation() {
            if (!MineFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.SHARE_ACTIVITY).navigation();
            }
        }

        public void addGroup() {
            if (!MineFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.ADD_GROUP_ACTIVITY).navigation();
            }
        }

        public void watchHistory() {
            if (!MineFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.MINE_HISTORY_VIDEO_ACTIVITY).navigation();
            }
        }

        public void mineBuy() {
            if (!MineFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.MINE_BUY_VIDEO_ACTIVITY).navigation();
            }
        }

        public void mineCollect() {
            if (!MineFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.MINE_COLLECT_VIDEO_ACTIVITY).navigation();
            }
        }

        public void mineDownLoad() {
            if (!MineFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.MINE_DOWNLOAD_VIDEO_ACTIVITY).navigation();
            }
        }

        public void mineAttention() {
            if (!MineFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.MINE_ATTENTION_ACTIVITY).navigation();
            }
        }

        public void exchangeVip() {
            if (!MineFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.EXCHANGE_CENTER_ACTIVITY).navigation();
            }
        }

        public void customerService() {
            if (!MineFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.ONLINE_SERVICE_ACTIVITY).navigation();
            }
        }

        public void btnApplicationCenter() {
            if (!MineFragment.this.isOnClick()) {
                if (TextUtils.isEmpty(MineFragment.this.applicationCenterUrl)) {
                    ToastUtils.getInstance().showSigh("暫無可用應用");
                    return;
                }
                try {
                    Intent intent = new Intent();
                    intent.setAction("android.intent.action.VIEW");
                    intent.setData(Uri.parse(MineFragment.this.applicationCenterUrl));
                    MineFragment.this.startActivity(intent);
                } catch (Exception e) {
                    LogUtils.m63e("mine", e.toString());
                }
            }
        }
    }
}
